function foundcityid(city){
    var cityid;
    $.ajax({
        type: 'post',
        url:"http://39.108.233.68:8080/selSomeCity",
        async:false,
        data: {
            key:city

        },
        datatype:'json',
        success: function (data) {

            data1=JSON.stringify(data)
            console.log(data1);

            for (i in data.data)
            {
                cityid=data.data[i].id;
                // console.log(cityid);
            }
            // console.log(cityid);

        },
        error: function () {
            alert("error");
        }
    })
    console.log(cityid);
    return cityid;
}
$(function () {
    $("#increase_submit").click(function () {

        var id = Math.ceil(Math.random()*1000);
        console.log(id);
        var length = document.getElementById("increase_length").value;
        var startplace = document.getElementById("increase_startplace").value;

        var endplace = document.getElementById("increase_endplace").value;
        console.log(startplace)
        console.log(endplace)
        var    startpalceid=foundcityid(startplace);
        if(startpalceid==null)
        {
            alert("无此起点城市")
        }
        var   endplaceid=foundcityid(endplace);
        if(endplaceid==null)
        {
            alert("无此终点城市")
        }




        var days = document.getElementById("increase_days").value;
        var describetion = document.getElementById("increase_describetion").value;
        var entryfee = document.getElementById("increase_entryfee").value;
        var type = document.getElementById("increase_type").value;
        var routemeslist=[];
        var routemes= new Object();

        routemes.describetion=describetion;//经过城市

        routemeslist.push(routemes);

        if(increase_length!="" &&increase_startplace!=''&& increase_endplace!=""&& increase_days!=""&& increase_describetion!=""&& increase_entryfee!="") {

            $.ajax({
                    type: 'post',
                    url:"http://39.108.233.68:8080/insOneRoute" ,
                    data: {
                        id:id,
                        length:length,
                        days:days,
                        startplaceid:startpalceid,
                        endplaceid:endplaceid,
                        describetion:describetion,
                        entryfee:entryfee,
                        type:type,
                        // cityMesList:JSON.stringify(routemeslist),

                    },

                    success: function (data) {

                        alert("成功增加路线");
                    },
                    error: function () {
                        alert("error");
                    }
                }
            )
        }


        else {
            alert("所有内容均不能为空！")
        }
    })
})
